﻿using BCCommon;
using BCDto.TMS.VehicleCategoryReference;
using BCDto.TMS.VehicleType;
using BCService.TMS.VehicleTypeService;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Net;

namespace BCTMSRESTful.Controllers.Management.TMS.VehicleType
{
    /// <summary>
    /// 车辆类型
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class VehicleTypeController : ManagementBaseController
    {
        #region 私有变量

        private readonly IVehicleTypeService vehicleTypeService;

        #endregion 私有变量

        #region 构造函数

        public VehicleTypeController(IVehicleTypeService vehicleTypeService)
        {
            this.vehicleTypeService = vehicleTypeService;
        }

        #endregion 构造函数

        #region 公共方法

        /// <summary>
        /// 创建车辆类型
        /// </summary>
        /// <param name="dto"></param>
        /// <response code="200">创建车辆成功。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建车辆类型")]
        [ProducesResponseType(typeof(VehicleTypeDto), 200)]
        public IActionResult CreateVehicle([FromBody] VehicleTypeRequestDto dto)
        {
            var res = vehicleTypeService.Add(this.Admin, dto);
            return StatusCode((int)HttpStatusCode.Created, res);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <response code="201">数据修改成功。</response>
        /// <returns></returns>
        [HttpPut("{vehicle_type_id}")]
        [Log("修改车辆类型")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult Put([FromRoute(Name = "vehicle_type_id")] int vehicleTypeId, [FromBody] VehicleTypeRequestDto dto)
        {
            var res = vehicleTypeService.Update(this.Admin, vehicleTypeId, dto);
            return StatusCode((int)HttpStatusCode.OK, res);
        }

        /// <summary>
        /// 修改车辆类型启用状态
        /// </summary>
        /// <param name="vehicleTypeId">车辆类型id</param>
        /// <param name="auditStatusRequestDto">是否启用</param>
        /// <response code="200">True数据修改成功,false数据修改失败。</response>
        /// <returns></returns>
        [HttpPut("[action]/{vehicle_type_id}")]
        [Log("修改车辆类型启用状态")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult AuditStatus([FromRoute(Name = "vehicle_type_id")] int vehicleTypeId,
            [FromBody] AuditStatusRequestDto auditStatusRequestDto)
        {
            var res = vehicleTypeService.UpdateAuditStatus(this.Admin, vehicleTypeId, auditStatusRequestDto);
            return this.Ok(res);
        }

        /// <summary>
        /// 通过车辆类型id获取车辆信息
        /// </summary>
        /// <param name="vehicleTypeId">车辆类型id</param>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [ProducesResponseType(typeof(VehicleTypeDto), 200)]
        [HttpGet("{vehicle_type_id}")]
        public IActionResult Get([FromRoute(Name = "vehicle_type_id")] int vehicleTypeId)
        {
            var data = vehicleTypeService.GetById(vehicleTypeId);
            return Ok(data);
        }

        /// <summary>
        /// 已存在车型名称列表
        /// </summary>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleTypeDto>), 200)]
        public IActionResult VehicleTypeNameList()
        {
            return Ok(vehicleTypeService.VehicleNameList());
        }

        /// <summary>
        /// 列表分页条件查询
        /// </summary>
        /// <param name="categoryReferenceIdStr">车辆分类对应Id</param>
        /// <param name="vehicleTypeId">车辆类型Id</param>
        /// <param name="vehicleTypeEnum">车辆所属类型（对应字典引用检索键）</param>
        /// <param name="maxStartWeight">最大开始载重</param>
        /// <param name="maxEndWeight">最大结束载重</param>
        /// <param name="maxStartStere">车辆最大起始载货立方</param>
        /// <param name="maxEndStere">车辆最大结束载货立方</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<VehicleTypeDto>), 200)]
        public IActionResult PageWhereList(
            [FromQuery(Name = "category_reference_id")] string categoryReferenceIdStr,
            [FromQuery(Name = "vehicle_type_id")] int? vehicleTypeId,
            [FromQuery(Name = "vehicle_type_enum")] string vehicleTypeEnum,
            [FromQuery(Name = "max_start_weight")] int? maxStartWeight,
            [FromQuery(Name = "max_end_weight")] int? maxEndWeight,
            [FromQuery(Name = "max_start_stere")] decimal? maxStartStere,
            [FromQuery(Name = "max_end_stere")] decimal? maxEndStere,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var data = vehicleTypeService.PageWhereList(this.Admin, categoryReferenceIdStr, vehicleTypeId, vehicleTypeEnum, maxStartWeight, maxEndWeight,
                maxStartStere, maxEndStere, enabled, pageIndex, pageSize);
            return Ok(data);
        }

        #region 车型分类

        /// <summary>
        /// 车型分类列表
        /// </summary>
        /// <param name="vehicleTypeId">车型ID</param>
        /// <response code="200">数据查询成功。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleCategoryReferenceDto>), 200)]
        public IActionResult CategoryReferenceList([FromQuery(Name = "vehicle_type_id")]int? vehicleTypeId)
        {
            var data = vehicleTypeService.GetCategoryReferenceList(vehicleTypeId);

            return Ok(data);
        }

        #endregion 车型分类

        #endregion 公共方法
    }
}
